home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Overview / TESample / TESample.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  12.9 KB  |  338 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware TextEdit Sample Application
  6. #
  7. #    TESample
  8. #
  9. #    TESample.h    -    Rez and C Include Source
  10. #
  11. #    Copyright © 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:
  15. #                1.00                08/88
  16. #                1.01                11/88
  17. #                1.02                04/89
  18. #                1.03                06/89
  19. #                1.04                06/92
  20. #
  21. #    Components:
  22. #                TESample.p            June 1, 1989
  23. #                TESample.c            June 1, 1989
  24. #                TESampleInit.c        June 4, 1992
  25. #                TESampleGlue.a        June 1, 1989
  26. #                TESample.r            June 1, 1989
  27. #                TESample.h            June 1, 1989
  28. #                PTESample.make        June 1, 1989
  29. #                CTESample.make        June 1, 1989
  30. #                TCTESample.π        June 4, 1992
  31. #                TCTESample.π.rsrc    June 4, 1992
  32. #                TCTESampleGlue.c    June 4, 1992
  33. #
  34. #    TESample is an example application that demonstrates how 
  35. #    to initialize the commonly used toolbox managers, operate 
  36. #    successfully under MultiFinder, handle desk accessories and 
  37. #    create, grow, and zoom windows. The fundamental TextEdit 
  38. #    toolbox calls and TextEdit autoscroll are demonstrated. It 
  39. #    also shows how to create and maintain scrollbar controls.
  40. #
  41. #    It does not by any means demonstrate all the techniques you 
  42. #    need for a large application. In particular, Sample does not 
  43. #    cover exception handling, multiple windows/documents, 
  44. #    sophisticated memory management, printing, or undo. All of 
  45. #    these are vital parts of a normal full-sized application.
  46. #
  47. #    This application is an example of the form of a Macintosh 
  48. #    application; it is NOT a template. It is NOT intended to be 
  49. #    used as a foundation for the next world-class, best-selling, 
  50. #    600K application. A stick figure drawing of the human body may 
  51. #    be a good example of the form for a painting, but that does not 
  52. #    mean it should be used as the basis for the next Mona Lisa.
  53. #
  54. #    We recommend that you review this program or Sample before 
  55. #    beginning a new application. Sample is a simple app. which doesn’t 
  56. #    use TextEdit or the Control Manager.
  57. #
  58. ------------------------------------------------------------------------------*/
  59.  
  60. /* Function prototypes for all functions in this program. */
  61. /* In MPW 3.0 we can use actual prototypes for parameter type checking. */
  62. /* A/UX C does not grok prototypes, so eliminate them under A/UX */
  63. #ifndef rez
  64.   #ifndef AUX
  65.     void AlertUser( short error );
  66.     void EventLoop( void );
  67.     void DoEvent( EventRecord *event );
  68.     void AdjustCursor( Point mouse, RgnHandle region );
  69.     void GetGlobalMouse( Point *mouse );
  70.     void DoGrowWindow( WindowPtr window, EventRecord *event );
  71.     void DoZoomWindow( WindowPtr window, short part );
  72.     void ResizeWindow( WindowPtr window );
  73.     void GetLocalUpdateRgn( WindowPtr window, RgnHandle localRgn );
  74.     void DoUpdate( WindowPtr window );
  75.     void DoDeactivate( WindowPtr window );
  76.     void DoActivate( WindowPtr window, Boolean becomingActive );
  77.     void DoContentClick( WindowPtr window, EventRecord *event );
  78.     void DoKeyDown( EventRecord *event );
  79.     unsigned long GetSleep( void );
  80.     void CommonAction( ControlHandle control, short *amount );
  81.     pascal void VActionProc( ControlHandle control, short part );
  82.     pascal void HActionProc( ControlHandle control, short part );
  83.     void DoIdle( void );
  84.     void DrawWindow( WindowPtr window );
  85.     void AdjustMenus( void );
  86.     void DoMenuCommand( long menuResult );
  87.     void DoNew( void );
  88.     Boolean DoCloseWindow( WindowPtr window );
  89.     void Terminate( void );
  90.     void Initialize( void );
  91.     void BigBadError( short error );
  92.     void GetTERect( WindowPtr window, Rect *teRect );
  93.     void AdjustViewRect( TEHandle docTE );
  94.     void AdjustTE( WindowPtr window );
  95.     void AdjustHV( Boolean isVert, ControlHandle control, TEHandle docTE,
  96.                     Boolean canRedraw );
  97.     void AdjustScrollValues( WindowPtr window, Boolean canRedraw );
  98.     void AdjustScrollSizes( WindowPtr window );
  99.     void AdjustScrollbars( WindowPtr window, Boolean needsResize );
  100.     pascal void PascalClickLoop();
  101.     pascal TEClickLoopUPP GetOldClickLoop();
  102.     Boolean IsAppWindow( WindowPtr window );
  103.     Boolean IsDAWindow( WindowPtr window );
  104.     Boolean TrapAvailable( short tNumber, TrapType tType );
  105.   #else
  106.     void AlertUser( );
  107.     void EventLoop( );
  108.     void DoEvent( );
  109.     void AdjustCursor( );
  110.     void GetGlobalMouse( );
  111.     void DoGrowWindow( );
  112.     void DoZoomWindow( );
  113.     void ResizeWindow( );
  114.     void GetLocalUpdateRgn( );
  115.     void DoUpdate( );
  116.     void DoDeactivate( );
  117.     void DoActivate( );
  118.     void DoContentClick( );
  119.     void DoKeyDown( );
  120.     unsigned long GetSleep( );
  121.     void CommonAction( );
  122.     void VActionProc( );
  123.     void HActionProc( );
  124.     void DoIdle( );
  125.     void DrawWindow( );
  126.     void AdjustMenus( );
  127.     void DoMenuCommand( );
  128.     void DoNew( );
  129.     Boolean DoCloseWindow( );
  130.     void Terminate( );
  131.     void Initialize( );
  132.     void BigBadError( ); 
  133.     void GetTERect( );
  134.     void AdjustViewRect( );
  135.     void AdjustTE( );
  136.     void AdjustHV( );
  137.     void AdjustScrollValues( );
  138.     void AdjustScrollSizes( );
  139.     void AdjustScrollbars( );
  140.     void PascalClickLoop();
  141.     TEClickLoopUPP GetOldClickLoop();
  142.     Boolean IsAppWindow( );
  143.     Boolean IsDAWindow( );
  144.     Boolean TrapAvailable( );
  145.   #endif
  146. #endif
  147.  
  148. /*    These #defines correspond to values in the Pascal source code.
  149.     TESample.c and TESample.r include this file. */
  150.  
  151. /*    Determining an application's minimum size to request from MultiFinder depends
  152.     on many things, each of which can be unique to an application's function,
  153.     the anticipated environment, the developer's attitude of what constitutes
  154.     reasonable functionality and performance, etc. Here is a list of some things to
  155.     consider when determining the minimum size (and preferred size) for your
  156.     application. The list is pretty much in order of importance, but by no means
  157.     complete.
  158.     
  159.     1.    What is the minimum size needed to give almost 100 percent assurance
  160.         that the application won't crash because it ran out of memory? This
  161.         includes not only things that you do have direct control over such as
  162.         checking for NIL handles and pointers, but also things that some
  163.         feel are not so much under their control such as QuickDraw and the
  164.         Segment Loader.
  165.         
  166.     2.    What kind of performance can a user expect from the application when
  167.         it is running in the minimum memory configuration? Performance includes
  168.         not only speed in handling data, but also things like how many documents
  169.         can be opened, etc.
  170.         
  171.     3.    What are the typical sizes of scraps is [a boy dog] that a user might
  172.         wish to work with when lauching or switching to your application? If
  173.         the amount of memory is too small, the scrap may get lost [will have
  174.         to be shot]. This can be quite frustrating to the user.
  175.         
  176.     4.    The previous items have concentrated on topics that tend to cause an
  177.         increase in the minimum size to request from MultiFinder. On the flip
  178.         side, however, should be the consideration of what environments the
  179.         application may be running in. There may be a high probability that
  180.         many users with relatively small memory configurations will want to
  181.         avail themselves of your application. Or, many users might want to use it
  182.         while several other, possibly related/complementary applications are
  183.         running. If that is the case, it would be helpful to have a fairly
  184.         small minimum size.
  185.     
  186.     What we did for TESample:
  187.     
  188.         We determined the smallest heap size that TESample could have and still
  189.         run (22K). For the preferred size we added enough space to permit:
  190.             a. a maximum size TextEdit text handle (32000 characters)
  191.             b. a maximum usable TextEdit scrap (32000 characters)
  192.             b. a maximum scrap as a result of Copy (32000 characters)
  193.             d. a little performance cushion (see 2, above) (10K)
  194.         Result: 122K for preferred size
  195.         
  196.         For the minimum size we took the 22K and then scaled down our requirements
  197.         for a,b, and c above. We thought that providing 16K more would be lean
  198.         and mean (see 4, above).
  199.         Result: 38K for minimum size
  200. */
  201.  
  202. #define kPrefSize                122
  203. #define kMinSize                38
  204.     
  205. /* The following constants are used to identify menus and their items. The menu IDs
  206.    have an "m" prefix and the item numbers within each menu have an "i" prefix. */
  207. #define    mApple                    128        /* Apple menu */
  208. #define    iAbout                    1
  209.  
  210. #define    mFile                    129        /* File menu */
  211. #define    iNew                    1
  212. #define    iClose                    4
  213. #define    iQuit                    12
  214.  
  215. #define    mEdit                    130        /* Edit menu */
  216. #define    iUndo                    1
  217. #define    iCut                    3
  218. #define    iCopy                    4
  219. #define    iPaste                    5
  220. #define    iClear                    6
  221.  
  222. /*    1.01 - kTopLeft - This is for positioning the Disk Initialization dialogs. */
  223.  
  224. #define kDITop                    0x0050
  225. #define kDILeft                    0x0070
  226.  
  227. /* 1.01 - changed constants to begin with 'k' for consistency, except for resource IDs */
  228. /*    kTextMargin is the number of pixels we leave blank at the edge of the window. */
  229. #define kTextMargin                2
  230.  
  231. /* kMaxOpenDocuments is used to determine whether a new document can be opened
  232.    or created. We keep track of the number of open documents, and disable the
  233.    menu items that create a new document when the maximum is reached. If the
  234.    number of documents falls below the maximum, the items are enabled again. */
  235. #define    kMaxOpenDocuments        1
  236.     
  237. /*    kMaxDocWidth is an arbitrary number used to specify the width of the TERec's
  238.     destination rectangle so that word wrap and horizontal scrolling can be
  239.     demonstrated. */
  240. #define    kMaxDocWidth            576
  241.     
  242. /* kMinDocDim is used to limit the minimum dimension of a window when GrowWindow
  243.     is called. */
  244. #define    kMinDocDim                64
  245.  
  246. /*    kControlInvisible is used to 'turn off' controls (i.e., cause the control not
  247.     to be redrawn as a result of some Control Manager call such as SetCtlValue)
  248.     by being put into the contrlVis field of the record. kControlVisible is used
  249.     the same way to 'turn on' the control. */
  250. #define kControlInvisible        0
  251. #define kControlVisible            0xFF
  252.  
  253. /*    kScrollbarAdjust and kScrollbarWidth are used in calculating
  254.     values for control positioning and sizing. */
  255. #define kScrollbarWidth            16
  256. #define kScrollbarAdjust        (kScrollbarWidth - 1)
  257.  
  258. /*    kScrollTweek compensates for off-by-one requirements of the scrollbars
  259.  to have borders coincide with the growbox. */
  260. #define kScrollTweek            2
  261.     
  262. /*    kCrChar is used to match with a carriage return when calculating the
  263.     number of lines in the TextEdit record. kDelChar is used to check for
  264.     delete in keyDowns. */
  265. #define kCrChar                    13
  266. #define kDelChar                8
  267.     
  268. /*    kButtonScroll is how many pixels to scroll horizontally when the button part
  269.     of the horizontal scrollbar is pressed. */
  270. #define kButtonScroll            4
  271.     
  272. /*    kMaxTELength is an arbitrary number used to limit the length of text in the TERec
  273.     so that various errors won't occur from too many characters in the text. */
  274. #define    kMaxTELength            32000
  275.  
  276. /* kSysEnvironsVersion is passed to SysEnvirons to tell it which version of the
  277.    SysEnvRec we understand. */
  278. #define    kSysEnvironsVersion        1
  279.  
  280. /* kOSEvent is the event number of the suspend/resume and mouse-moved events sent
  281.    by MultiFinder. Once we determine that an event is an OSEvent, we look at the
  282.    high byte of the message sent to determine which kind it is. To differentiate
  283.    suspend and resume events we check the resumeMask bit. */
  284. #define    kOSEvent                app4Evt    /* event used by MultiFinder */
  285. #define    kSuspendResumeMessage    1        /* high byte of suspend/resume event message */
  286. #define    kResumeMask                1        /* bit of message field for resume vs. suspend */
  287. #define    kMouseMovedMessage        0xFA    /* high byte of mouse-moved event message */
  288. #define    kNoEvents                0        /* no events mask */
  289.  
  290. /* 1.01 - kMinHeap - This is the minimum result from the following
  291.      equation:
  292.             
  293.             ORD(GetApplLimit) - ORD(ApplicZone)
  294.             
  295.      for the application to run. It will insure that enough memory will
  296.      be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  297.      application, and still give the application some 'breathing room'.
  298.      To derive this number, we ran under a MultiFinder partition that was
  299.      our requested minimum size, as given in the 'SIZE' resource. */
  300.      
  301. #define    kMinHeap                 (29 * 1024)
  302.     
  303. /* 1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called
  304.      at initialization time, for the application to run. This number acts
  305.      as a double-check to insure that there really is enough memory for the
  306.      application to run, including what has been taken up already by
  307.      pre-loaded resources, the scrap, code, and other sundry memory blocks. */
  308.      
  309. #define    kMinSpace                (20 * 1024)
  310.  
  311. /*    kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions. */
  312. #define kExtremeNeg                -32768
  313. #define kExtremePos                (32767 - 1)    /* required to address an old region bug */
  314.     
  315. /* kTESlop provides some extra security when pre-flighting edit commands. */
  316. #define    kTESlop                    1024
  317.  
  318. /* The following are indicies into STR# resources. */
  319. #define    eWrongMachine            1
  320. #define    eSmallSize                2
  321. #define    eNoMemory                3
  322. #define    eNoSpaceCut                4
  323. #define    eNoCut                    5
  324. #define    eNoCopy                    6
  325. #define    eExceedPaste            7
  326. #define    eNoSpacePaste            8
  327. #define    eNoWindow                9
  328. #define    eExceedChar                10
  329. #define    eNoPaste                11
  330.  
  331. #define    rMenuBar    128                /* application's menu bar */
  332. #define    rAboutAlert    128                /* about alert */
  333. #define    rUserAlert    129                /* user error alert */
  334. #define    rDocWindow    128                /* application's window */
  335. #define    rVScroll    128                /* vertical scrollbar control */
  336. #define    rHScroll    129                /* horizontal scrollbar control */
  337. #define    kErrStrings    128                /* error string list */
  338.